package com.itheima.itheima.controller;

import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkitem")
public class CheckItemController {

    @Reference
    private CheckItemService checkItemService;

    @RequestMapping("/addorupdate")
    public Boolean add(@RequestBody CheckItem checkItem){
//        boolean save = checkItemService.save(checkItem);
        boolean b = checkItemService.saveOrUpdate(checkItem);
        System.out.println("修改");
        return  b;
    }

    @RequestMapping("/find")
    public List<CheckItem> findAll(){
        System.out.println("查询全部");
        return checkItemService.findAll();
    }

    @RequestMapping("deleteCheckItemById/{id}")
    @ApiOperation(value = "删除检查项", notes = "根据检查项id 逻辑删除检查项")
    public Boolean deleteCheckItemById(@PathVariable("id") Long id) {
        boolean b = checkItemService.deleteById(id);
        return b;
    }

    @RequestMapping("findbypage")
    public PageResult findByPage(@RequestBody QueryPageBean queryPageBean){
        System.out.println("分页查询"+queryPageBean);
        PageResult pageResult = checkItemService.findByPage(queryPageBean);
        System.out.println(pageResult);
        return pageResult;
    }


}
